import React, { Component } from 'react';
import { List, Avatar } from 'antd';
import { connect } from 'react-redux';

const data = [{
    "from": "62980",
    "to": "217",
    "type": "chat",
    "msg": {
        "message": "😊",
        "type": "text"
    },
    "ext": {},
    "num": 0,
    "deleted": false,
    "create_at": 1520217899,
    "update_at": 1520217899
  }, {
    "from": "22428",
    "to": "217",
    "type": "chat",
    "msg": {
        "message": "😄😄",
        "type": "text"
    },
    "ext": {},
    "num": 0,
    "deleted": false,
    "create_at": 1520282463,
    "update_at": 1520282463
}]

class ConversationList extends Component {
    componentDidMount() {
        const { socket,  } = this.props;
        socket.send('/v1/get/all/conversation', {last_pull: 0}, (data) => {
            console.log(data)
            this.setState()
        })
        // window.ws
    }
    render () {
        return (
            <div>
                <List
                    dataSource={data}
                    renderItem={item => (
                        <List.Item key={item.from}>
                            <List.Item.Meta
                                avatar={<Avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />}
                                title={item.from}
                                description={item.to}
                            />
                        </List.Item>
                    )}>
                </List>
            </div>
        )
    }
}


function mapStateToProps(state) {
	return {
		conversation: state.conversation
	}
}

function mapDispatchToProps(dispatch) {
	return {
        fetchAllConversation: dispatch()
    }
}


export default connect(
    mapStateToProps,
    mapDispatchToProps
)(ConversationList);
